import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SquareLIst extends StatefulWidget {
  const SquareLIst({super.key});
  @override
  State<SquareLIst> createState() => _SquareLIst();
}

class _SquareLIst extends State<SquareLIst> {
  @override
  void initState() {
    super.initState();
    //_loadInitialData();
    // _scrollController.addListener(_scrollListener); // 绑定滚动监听
  }

  @override
  void dispose() {
    // _scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
// 总高度 = 状态栏高度 + AppBar 内容高度
//final totalHeight = MediaQuery.of(context).padding.top + kToolbarHeight;
    final screenHeight = MediaQuery.of(context).padding.top+15;
    return Stack(children: [
      Positioned(
        child: Image.asset(
          'static/images/hometop.png',
          fit: BoxFit.fitWidth,
        ),
      ),
      LayoutBuilder(
        builder: (context, constraints) {
          final screenWidth = constraints.maxWidth;
          final spacing = 10.0; // 间距
          final itemWidth = (screenWidth - spacing) / 2;
          const itemHeight = 269.0; // 固定高度
          return GestureDetector(
            onTap: () {
              Get.dialog(
                AlertDialog(
                  backgroundColor: Colors.transparent,
                  content: Stack(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(15.0),
                        child: Image.asset(
                          'static/qidai.png',
                          width: 250,
                          fit: BoxFit.fitWidth,
                        ),
                      ),
                    ],
                  ),
                ),
              );
           
            },
            child: GridView.builder(
              padding: EdgeInsets.only(top: screenHeight, left: 15, right: 15),
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2,
                crossAxisSpacing: spacing,
                mainAxisSpacing: spacing,
                childAspectRatio: itemWidth / itemHeight,
              ),
              itemCount: 8,
              itemBuilder: (context, index) {
                return Stack(
                  fit: StackFit.expand,
                  children: [
                    ClipRRect(
                      borderRadius: BorderRadius.circular(7),
                      child: Image.asset(
                        'static/vv.jpg',
                        fit: BoxFit.cover,
                      ),
                    ),
                    Positioned(
                      top: 20,
                      left: 50,
                      right: 50,
                      child: 
                      Image.asset(
                        'static/bligin.png',
                        width: 70,
                        fit: BoxFit.fitWidth,
                      )
                    ),
                    Positioned(
                      top: 110,
                      left: 20,
                      right: 20,
                      child: 
                      Image.asset(
                        'static/d3.png',
                        fit: BoxFit.fitWidth,
                      )
                    ),

                    Positioned(
                      bottom: 10,
                      left: 10,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                            padding: EdgeInsets.only(top: 2, bottom: 3),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular((15)),
                              gradient: LinearGradient(
                                colors: [
                                  Color(0xff2189E7),
                                  Color(0xffBF67F8),
                                ], // 定义颜色列表
                                begin: Alignment.topLeft, // 渐变开始的位置
                                end: Alignment.bottomRight, // 渐变结束的位置
                              ),
                            ),
                            width: 45,
                            child: Text('直播中',
                                style: TextStyle(
                                    fontSize: 10, color: Color(0xffffffff))),
                          ),
                          Container(
                            margin: EdgeInsets.only(top: 5, bottom: 5),
                            child: Text('@主播昵称',
                                style: TextStyle(
                                    fontSize: 14, color: Color(0xffffffff))),
                          ),
                          Container(
                            alignment: Alignment.centerLeft,
                            child: Text('神秘嘉宾空降！@×× 现身连麦！',
                                style: TextStyle(
                                    fontSize: 11, color: Color(0xffffffff))),
                          ),
                        ],
                      ),
                    ),
                  ],
                );
              },
            ),
          );
        },
      ),
    ]);
  }
}
